package Graph;

import java.util.*;

public class 蓝桥王国 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int M = scanner.nextInt();

        Integer[][] dist = new Integer[N + 1][N + 1];

        for (int i = 1; i < dist.length; i++) {
            Arrays.fill(dist[i], 1000000000);
        }
        for (int i = 1; i < dist.length; i++) {
            for (int j = 1; j < dist.length; j++) {
                if (i == j) {
                    dist[i][j] = 0;
                }
            }
        }

        for (int i = 1; i <= N; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            dist[a][b] = c;
        }

        for (int k = 1; k < dist.length; k++) {
            for (int i = 1; i < dist.length; i++) {
                for (int j = 1; j < dist.length; j++) {
                    if (dist[i][k] + dist[k][j] <= dist[i][j]) {
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }
                }
            }
        }

        System.out.println(dist[1][1] + " " + dist[1][2] + " " + dist[1][3]);
    }

    public static void print(Integer[][] dist) {
        for (Integer[] integers : dist) {
            System.out.println(Arrays.toString(integers));
        }

    }


}
